﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web;
using System.IO;
using System.Text.RegularExpressions;
using Light.Utility;

namespace WxPayAPI
{
    public class PagePayOrder : Page
    {
        protected string OpenId = "";
        protected string BodyStr = ""; 
        protected decimal TotalFee = 0;
        protected string OrderCode = "";

        /// <summary>
        /// 订单查询页
        /// </summary>
        protected string orderQueryPageUrl =System.Web.Configuration.WebConfigurationManager.AppSettings["OrderQueryPageUrl"]; 
        /// <summary>
        /// 成功失败页 
        /// </summary>
        protected string PayResultPageUrl =System.Web.Configuration.WebConfigurationManager.AppSettings["PayResultPageUrl"];
        /// <summary>
        /// 输入密码页
        /// </summary>
        protected string JsApiPayPageUrl =System.Web.Configuration.WebConfigurationManager.AppSettings["JsApiPayPageUrl"];

        protected override void OnLoad(EventArgs e)
        {
            if (!IsPostBack)
            {
                OpenId = WebHelper.GetRequest("openid", "");
                ViewState["openid"] = OpenId;
            }
            base.OnLoad(e);
        } 

        protected void OrderSubmit()
        {
            OpenId = ViewState["openid"].ToString();
            string url = JsApiPayPageUrl + "?openid=" + OpenId + "&total_fee=" + TotalFee + "&orderCode=" + OrderCode + "&PayResultPageUrl=" + HttpUtility.UrlEncode(PayResultPageUrl) + "&orderQueryPageUrl=" + orderQueryPageUrl + "&body=" + BodyStr; 
            WxPayAPI.Log.Debug(this.GetType().ToString(), "orderCode " + OrderCode + " Will Redirect to URL : " + url);
            Response.Redirect(url);
        }

    }
}
